<template>
  <div class="x-contaniner">
    <div class="tree-head" v-if="showTitle">
      <span><i class="el-icon-map-location"></i>区域：</span>
    </div>
    <el-tree
      class="tree-box"
      :data="treeData"
      :props="defaultProps"
      @node-click="handleNodeClick"
    ></el-tree>
  </div>
</template>

<script>
import { getArea } from "@/api/common";
export default {
  name: "XhArea",

  props: {
    showTitle: { type: Boolean, default: true },
  },

  data() {
    return {
      //tree
      treeData: [{ Zoneid: "", Zonename: "全部" }],
      defaultProps: {
        children: "Childzones",
        label: "Zonename",
      },
    };
  },

  mounted() {
    this.$nextTick(() => {
      this.getArea();
    });
  },

  methods: {
    //tree Area
    getArea() {
      getArea().then((res) => {
        this.treeData = this.treeData.concat(res.Data);
      });
    },

    //select
    handleNodeClick(data) {
      this.$emit("select", data);
    },
  },
};
</script>

<style lang="scss" scoped>
.x-contaniner {
  width: 100%;
  height: 100%;
  .tree-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 15px;
    height: 50px;
    line-height: 50px;
    border-bottom: 1px solid #eee;
    font-size: 15px;
    font-weight: bold;
    span {
      display: block;
    }
    i {
      margin-right: 10px;
      font-weight: bold;
      font-size: 15px;
    }
  }

  .tree-box {
    // width: 260px;
    // max-width: 260px;
    width: 100%;
    max-width: 100%;
    height: calc(100% - 50px);
    overflow: auto;
    padding: 15px 5px;
  }
  .el-tree {
    max-width: 100%; //200px;
    overflow: auto;
  }

  ::v-deep {
    .el-tree > .el-tree-node {
      display: inline-block;
      min-width: 100%;
    }
  }
}
</style>